package com.ry.novel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ry.novel.model.entity.BookIndex;
import com.ry.novel.service.BookIndexService;
import com.ry.novel.model.dto.BookIndexInfo;
import com.ry.novel.model.dto.condition.BookIndexQuery;
import com.ry.novel.model.resp.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ry
 * @since 2022-03-27 19:12
 **/
@Slf4j
@RestController
@RequestMapping("/bookIndex")
public class BookIndexController {

    @Autowired
    private BookIndexService bookIndexService;

    @PostMapping("/queryBookIndex")
    public Result<Page<BookIndexInfo>> queryBookIndex(@RequestBody BookIndexQuery query){
        Page<BookIndexInfo> infoPage = bookIndexService.queryBookIndexInfo(query);

        return Result.ok(infoPage);
    }

    @PostMapping("/updateBookIndex")
    public Result<Void> updateBookIndex(@RequestBody BookIndexInfo bookIndexInfo){
        bookIndexService.updateIndex(bookIndexInfo);

        return Result.ok();
    }

    @PostMapping("/addBookIndex")
    public Result<Void> addBookIndex(@RequestBody BookIndexInfo bookIndexInfo){
        bookIndexService.addIndex(bookIndexInfo);

        return Result.ok();
    }

    @PostMapping("/deleteBookIndex")
    public Result<Void> deleteBookIndex(@RequestParam("id")Long id){
        bookIndexService.deleteIndex(id);

        return Result.ok();
    }

    @PostMapping("/queryBookIndexByBookId")
    public Result<List<BookIndexInfo>> queryBookIndexByBookId(@RequestParam("bookId")Long bookId){
        return Result.ok(bookIndexService.queryBookIndexByBookId(bookId));
    }

    @GetMapping("/queryBookIndexById")
    public Result<BookIndexInfo> queryBookIndexById(@RequestParam("id")Long id){
        return Result.ok(bookIndexService.queryBookIndexById(id));
    }
}
